package dao.Impl;


import dao.TbaseorderDao;
import pojo.Tbaseorder;
import util.BaseDao;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class TbaseorderDaoImpl extends BaseDao implements TbaseorderDao {
    @Override
    public int add(Tbaseorder ts) {
        int shu = 0;
        String sql = "insert into t_base_order (user_id, account, user_address, create_time, amount, order_no)\n" +
                "values (?,?,?,now(),?,?)";
        getConnection();
        try {
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setObject(1, ts.getUserId());
            ps.setObject(2, ts.getAccount());
            ps.setObject(3, ts.getUserAddress());
            ps.setObject(4, ts.getAmount());
            ps.setObject(5, ts.getOrderNo());
            ps.executeUpdate();
            rs = ps.getGeneratedKeys();
            if (rs.next()) {
                shu = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return shu;
    }


}
